﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Configuration;
using SelfMadeMillionaire.Core.Services;

namespace SelfMadeMillionaire.Web.Infrastructure.Controllers
{
    public class LogoController : BaseController
    {
        ISubscriberService _subscriberService;

        public LogoController(ISubscriberService subscriberService)
		{
			_subscriberService = subscriberService;
		}

        [HttpGet]
        public void Index(string mailing)
        {
            if (!string.IsNullOrEmpty(mailing))
                _subscriberService.UpdateMODetail_EmailOpen(mailing);
            
            if (Session["isSessionActive"] == null)
            {
                try
                {
                    int hit_id = 0;
                    LogHit(WebConfigurationManager.ConnectionStrings["DataContext"].ConnectionString,
                                Request.Headers["Referer"] + "",
                                Request.ServerVariables["SCRIPT_NAME"],
                                Request.ServerVariables["REMOTE_ADDR"],
                                Request.ServerVariables["HTTP_USER_AGENT"],
                                Request.Url.AbsoluteUri);
                    Session["isSessionActive"] = 1;
                    //Session[SessionKeys.Hit_ID] = hit_id;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            string img = Server.MapPath("~/Content/images/company_logo_1.png");
            Response.WriteFile(img);
            Response.ContentType = "image/png";
        }
    }
}
